﻿using System.Collections.Generic;
using System.Text;
using HavardFjaer.Pushover.Client;

namespace HavardFjaer.Pushover.Console
{
    internal class Program
    {
        /*
        POST an HTTP request to https://api.pushover.net/1/messages.json with the following parameters:
            token (required) - your application's API token
            user (required) - the identifier of your user (or you), viewable when logged into the dashboard
            message (required) - your message
         */

        private static void Main(string[] args)
        {
            const string token = "dn9odn1SLz8RNxvqk8afkkiH460QuZ";
            const string user = "kJiVnO2qUvujYNQxzTrsUcWMe4Y3Iv";

            var validation = new PushoverValidator(token, user, ResponseFormat.Json);
            System.Console.WriteLine(validation.Validate());

            var messageSender = new PushoverMessageSender(token, user, ResponseFormat.Json);
            string message = args.Length > 0 ? GetMessageFromArgs(args) : "I'm saying HI! to the client developer :-)";
            System.Console.WriteLine(messageSender.SendMessage(message, title: "Pushover Client", priority: MessagePriority.High));

            System.Console.ReadKey();
        }

        private static string GetMessageFromArgs(IEnumerable<string> args)
        {
            var sb = new StringBuilder();
            foreach (string arg in args)
            {
                sb.Append(arg);
                sb.Append(" ");
            }
            return sb.ToString();
        }
    }
}